package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.StockOutcomeBill;
import cn.wolfcode.crm.mapper.OrderMapper;
import cn.wolfcode.crm.mapper.StockOutcomeBillMapper;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.IStockOutcomeBilService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StockOutcomeBillServiceImpl implements IStockOutcomeBilService {
    //关联mapper
    @Autowired
    private StockOutcomeBillMapper stockOutcomeBillMapper;
    @Autowired
    private OrderMapper orderMapper;


    @Override
    public int deleteByPrimaryKey(Long id) {
        return stockOutcomeBillMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void insert(StockOutcomeBill record,String remark) {

        stockOutcomeBillMapper.insert(record);

        System.out.println(record);
        // 保存订单信息
        orderMapper.insertRelation(record.getProduct().getId(), record.getId(), remark, 1);
    }

    @Override
    public StockOutcomeBill selectByPrimaryKey(Long id) {
        return stockOutcomeBillMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<StockOutcomeBill> selectAll() {
        return stockOutcomeBillMapper.selectAll();
    }

    @Override
    public int updateByPrimaryKey(StockOutcomeBill record) {




        return stockOutcomeBillMapper.updateByPrimaryKey(record);
    }

    @Override
    public PageResult query(QueryObject qo) {
        //查询总记录数据
        int total = stockOutcomeBillMapper.queryForCount(qo);
        List<StockOutcomeBill> rows = stockOutcomeBillMapper.queryForList(qo);

        return new PageResult(total,rows);
    }

}
